
Partial Class Case_casePersonalInfo
    Inherits System.Web.UI.UserControl
    Implements IPermission

    Public ReadOnly Property CaseStatusSelection() As Integer
        Get
            Return Me.CaseStatusEditInputControl.SelectedValue
        End Get
    End Property

    Public ReadOnly Property SectionName() As String Implements IPermission.SectionName
        Get
            Return "Personal"
        End Get
    End Property

    Public ReadOnly Property StatusEditable() As Boolean
        Get
            Return Me.CaseStatusEditInputControl.Editable
        End Get
    End Property

    Public ReadOnly Property ControlCollection() As System.Web.UI.ControlCollection Implements IPermission.ControlCollection
        Get
            Return Me.Controls
        End Get
    End Property

    Public ReadOnly Property EntityPermissionType() As Cdm.DataCore.UserSecurity.Permission.PermissionType Implements IPermission.EntityPermissionType
        Get
            Return Cdm.DataCore.UserSecurity.Permission.PermissionType.CasePersonal
        End Get
    End Property

    Public Property PrimaryObject() As Cdm.DataCore.ConfigurableObject Implements IPermission.PrimaryObject
        Get
            Dim pg As IPermission = Me.Page
            Return pg.PrimaryObject
        End Get
        Set(ByVal value As Cdm.DataCore.ConfigurableObject)
            BindDropDowns()
            EntityController.SetPagePropertiesFromObject(Me, True)
            Me.SpecialFieldPersonal.Editable = CheckEditable()
            Me.SpecialFieldPersonal.PrimaryObject = value

            If MedicaidNumberInputControl.Editable Then
                Me.MedicaidNumberInputControl.SetMaxTextLength(GetMaxMedicaidNumberLength())
            End If
        End Set
    End Property

    Private Function GetMaxMedicaidNumberLength() As Integer
        Dim C_DEFAULT_MAX_MEDICAIDNUMBER_LENGTH As Integer = 15
        If Not Application("MedicaidNumberLength") Is Nothing Then
            Return CInt(Application("MedicaidNumberLength"))
        Else
            Return C_DEFAULT_MAX_MEDICAIDNUMBER_LENGTH
        End If

    End Function

    ''' <summary>
    ''' Checks if the 
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function CheckEditable() As Boolean
        If Me.PrimaryObject.Id > 0 Then
            Return UserAuthorization.HasUpdatePermission(Me.EntityPermissionType)
        Else
            Return UserAuthorization.HasInsertPermission(Me.EntityPermissionType)
        End If

    End Function

    Protected Sub Page_Init(ByVal sender As Object, _
                            ByVal e As System.EventArgs) _
                            Handles Me.Init

        If Me.IsPostBack Then
            EntityController.SetPagePropertiesFromObject(Me, False)
            Me.SpecialFieldPersonal.Editable = CheckEditable()
            Me.SpecialFieldPersonal.PrimaryObject = Me.PrimaryObject
        End If

    End Sub
   

    Protected Sub Page_Load(ByVal sender As Object, _
                            ByVal e As System.EventArgs) _
                            Handles Me.Load

        Me.FirstNameInputControl.Visible = Me.FirstNameInputControl.Editable
        Me.LastNameInputControl.Visible = Me.LastNameInputControl.Editable

        If TypeOf Me.PrimaryObject Is Cdm.DataCore.Entities.Participant Then
            Dim t_Participant As Cdm.DataCore.Entities.Participant = CType(Me.PrimaryObject, Cdm.DataCore.Entities.Participant)
            Me.ParticipantIdValue.Text = t_Participant.Id.ToString()
        End If

    End Sub

    Public Sub ResetControls() Implements IPermission.ResetControls

    End Sub

    Private Sub BindDropDowns()

        Me.CaseStatusEditInputControl.DataSource = Cdm.DataCore.LookupTables.LuCaseStatus.ListAll(0, "Select Status")
        Me.CaseRaceInputControl.DataSource = Cdm.DataCore.LookupTables.LuRace.ListAll(0, "Select Race")
        Me.CountyInputControl.DataSource = Cdm.DataCore.LookupTables.LuCounty.ListAll(0, "Select County")
        Me.LocalProgramInputControl.DataSource = Cdm.DataCore.Entities.LocalProgram.ListAll(0, "Select Local Program")
        Me.GenderInputControl.DataSource = Cdm.DataCore.LookupTables.LuGender.ListAll(0, "Select Gender")
        Me.CountyInputControl.DataBind()
        Me.CaseStatusEditInputControl.DataBind()
        Me.CaseRaceInputControl.DataBind()
        Me.LocalProgramInputControl.DataBind()
        Me.GenderInputControl.DataBind()

    End Sub

    Public Sub SaveData()

        EntityController.SetObjectPropertiesFromPage(Me)
        Me.PrimaryObject.SpecialFieldsValues = Me.SpecialFieldPersonal.SaveSpecialFields()

    End Sub

    Public Sub SetParticipantId(ByVal newParticipantId As Integer)
        Me.ParticipantIdValue.Text = newParticipantId.ToString()
    End Sub

    Public Sub SetStatusId(ByVal newStatusId As Integer)
        Me.CaseStatusEditInputControl.Value = newStatusId.ToString()
    End Sub

End Class
